package com.xiaolin.oa.controller;

import com.xiaolin.oa.annotations.HasApi;
import com.xiaolin.oa.constants.ApiPermConstant;
import com.xiaolin.oa.model.dto.CurrentUser;
import com.xiaolin.oa.model.dto.UserLoginInfo;
import com.xiaolin.oa.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author xiaolin
 * @description 描述
 * @since 2024/7/18
 */
@RestController
@RequestMapping("/auth")
public class AuthController {
    @Autowired
    private AuthService authService;

    /**
     * 登录
     *
     * @return
     */
    @PostMapping("/login")
    public String login(@RequestBody UserLoginInfo userLoginInfo) {
        return authService.login(userLoginInfo);
    }

    /**
     * 获取用户信息
     *
     * @param request
     * @return
     */
    @HasApi(ApiPermConstant.COMMON_PERM)
    @GetMapping("/info")
    public CurrentUser info(HttpServletRequest request) {
        return authService.info(request);
    }

    /**
     * 注销
     *
     * @return
     */
    @HasApi(ApiPermConstant.COMMON_PERM)
    @PostMapping("/logout")
    public boolean logout(HttpServletRequest request) {
        return authService.logout(request);
    }
}
